package top.lemna.account.persistence;

import java.time.LocalDate;

import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Index;
import jakarta.persistence.Table;
import jakarta.validation.constraints.Digits;
import jakarta.validation.constraints.NotNull;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import top.lemna.account.domain.DebitCredit;
import top.lemna.common.Amount;

/**
 * 账户操作日志
 */
@Getter
@Builder
@ToString()
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@ NoArgsConstructor(access = AccessLevel.PRIVATE)
@Entity
// @NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
@Table(//
        name = "ac_account_log", //
        indexes = { @Index(columnList = "accountId") } //
)
public class AccountLog {

    /** ID */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /** 账户ID */
    @NotNull
    @lombok.NonNull
    @Column(columnDefinition = "bigint(19) NOT NULL COMMENT '账户ID'")
    private Long accountId;

    /** 操作金额 */
    @NotNull
    @lombok.NonNull
    @Convert(converter = AmountConverter.class)
    // @Digits(integer = 6, fraction = 2)
    @Column(columnDefinition = "DECIMAL(19,4) DEFAULT '0.00' COMMENT '操作金额'")
    private Amount amount;

    /** 操作后余额 */
    @NotNull
    @lombok.NonNull
    @Convert(converter = AmountConverter.class)
    @Column(columnDefinition = "DECIMAL(19,4) DEFAULT '0.00' COMMENT '操作后余额'")
    private Amount afterBalance;

    /** 借贷方向 */
    @NotNull
    @lombok.NonNull
    @Enumerated(EnumType.STRING)
    private DebitCredit debitCredit;

    /** 备注 */
    @Column(columnDefinition = "varchar(256) DEFAULT '' COMMENT '备注'")
    private String remark;

    /** 操作日期 */
    // @lombok.NonNull
    @NotNull
    @Column(columnDefinition = "datetime DEFAULT now() COMMENT '操作日期'")
    private LocalDate operDate = LocalDate.now();


}